
import GridAPI from '../api/grid.js';

export const Grid={
   state:{
      gridlist:[],
      grid_total_count:0,
      editGridStatus:-1,     //插入状态 0失败  1成功  -1不改变
      gridinfo:[],
      delGridStatus:-1,       //删除状态
	    allgridlist:[],
      //筛选条件
      grid_c_id:''
   },
   mutations:{
      setGridList(state,list){
          state.gridlist=list;
      },
      setGridTotalCount(state,total_count){
          state.grid_total_count=total_count;
      },
      setEditGridStatus(state,status){
          state.editGridStatus=status;
      },
      setGridInfo(state,info){
          state.gridinfo=info;
      },
      setDelGridStatus(state,status){
          state.delGridStatus=status;
      },
      setAllGridList(state,list){
          state.allgridlist=list;
      },
      setGridCId(state,c_id){
          state.grid_c_id=c_id;
      }
   },
   actions:{
      loadGridList(context,data){
          GridAPI.getGridList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setGridList',response.data.list);
                  context.commit('setGridTotalCount',response.data.total_count);
              }
          })
      },
      //插入Grid
      editGrid(context,data){
          GridAPI.editGrid(data).then(function(response){
              context.commit('setEditGridStatus',response.data.code);
          })
      },
      //获取详情
      loadGridInfo(context,data){
          GridAPI.getGridInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setGridInfo',response.data.info);
              }
          })
      },
      //删除
      delGrid(context,data){
          GridAPI.delGrid(data).then(function(response){
                context.commit('setDelGridStatus',response.data.code);
          })
      },
      //全部网格
      loadAllGridList(context,data){
          GridAPI.getAllGridList(data).then(function(response){
                context.commit('setAllGridList',response.data.list);
          })
      }
   },
   getters:{
      getGridList:state =>{
         return state.gridlist
      },
      getGridTotalCount: state =>{
         return state.grid_total_count
      },
      getEditGridStatus:state=>{
          return state.editGridStatus;
      },
      getGridInfo:state => {
          return state.gridinfo;
      },
      getDelGridStatus:state => {
          return state.delGridStatus;
      },
      getAllGridList:state => {
          return state.allgridlist;
      },
      getGridCid:state => {
          return state.grid_c_id;
      }
   }
}
